load SensitivityTestData.mat

%Apply linear regression fit to each Sensitivity Data Set
mdlTemp = fitlm(SenseVTempData(:,1),SenseVTempData(:,2));
mdlGrad1 = fitlm(SenseVsGradData(1:11,1),SenseVsGradData(1:11,2));
mdlGrad2 = fitlm(SenseVsGradData(12:22,1),SenseVsGradData(12:22,2));
mdlGradCorrect = fitlm(SenseVsGradDataCorrected(:,1),SenseVsGradDataCorrected(:,2));

tiledlayout(3,1)
nexttile % Plot Sensitivity Vs Temperature data
errorbar(SenseVTempData(:,1),SenseVTempData(:,2),SenseVTempError,SenseVTempError,TempError(1:11),TempError(1:11),'o')
grid on 
hold on
plot(SenseVTempData(:,1),(SenseVTempData(:,1)*mdlTemp.Coefficients.Estimate(2))+mdlTemp.Coefficients.Estimate(1),'--b');
mdlTemp.Coefficients
label = join([num2str(mdlTemp.Coefficients.Estimate(2)),'+/-', num2str(mdlTemp.Coefficients.SE(2)),' nT/C']); % label for legend including error of fit
legend('Sensitivity', label)
ylim([87 100.5])
title('Sensitivity VS Temperature')
disp(label)
xlabel('Temperature in C')
hold off

nexttile % Plot Sensitivity Vs Thermal Gradients Native
errorbar(SenseVsGradData(:,1),SenseVsGradData(:,2),SenseVsGradError,SenseVsGradError,TempError,TempError,'o')
hold on
label = join([num2str(mdlGrad1.Coefficients.Estimate(2)),'+/-', num2str(mdlGrad1.Coefficients.SE(2)),' nT/C']);% label for legend including error of fit
plot(SenseVsGradData(:,1),(SenseVsGradData(:,1)*mdlGrad1.Coefficients.Estimate(2))+mdlGrad1.Coefficients.Estimate(1),'.-.b');
mdlGrad1.Coefficients
grid on
hold on
ylim([94 100.5])
plot(SenseVsGradData(12:22,1),(SenseVsGradData(12:22,1)*mdlGrad2.Coefficients.Estimate(2))+mdlGrad2.Coefficients.Estimate(1),'--b');
labelNeg = join([num2str(mdlGrad2.Coefficients.Estimate(2)),'+/-', num2str(mdlGrad2.Coefficients.SE(2)),' nT/C']);% label for legend including error of fit
legend('Sensitivity', label,labelNeg)
disp(label)
title('Sensitivity VS Gradient (Raw)')
xlabel('Temperature in C')
mdlGrad2.Coefficients
hold off

nexttile % Plot Sensitivity Vs Thermal Gradients Corrected
errorbar(SenseVsGradDataCorrected(:,1),SenseVsGradDataCorrected(:,2),SenseVsGradError,SenseVsGradError,TempError,TempError,'o')
hold on
plot(SenseVsGradDataCorrected(:,1),(SenseVsGradDataCorrected(:,1)*mdlGradCorrect.Coefficients.Estimate(2))+mdlGradCorrect.Coefficients.Estimate(1)+0.04,'--b');
ylim([99.85 100.095])
mdlGradCorrect.Coefficients
label = join([num2str(mdlGradCorrect.Coefficients.Estimate(2)),'+/-', num2str(mdlGradCorrect.Coefficients.SE(2)),' nT/C']); % label for legend including error of fit
legend('Sensitivity', label)
disp(label)
title('Sensitivity VS Gradient (Corrected)')
grid on